package tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;

public class Ingredient implements Tag {

	
	private PageContext pageContext = null;
	private Tag parentTag = null;
	private String name = "";
	private Double price = 0.0;
	
	public Ingredient() {
	}
	
	@Override
	public int doEndTag() throws JspException {
		System.out.println("Ingredients.doEndTag()");
		try {
			String ingredient = "<input type='checkbox' id='" + name + "' name='ingredients-" + name + "' value='" + price + "' /><label for='" + name + "'>" + name +"</label><br />";
			pageContext.getOut().print(ingredient);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return 0;
		
	}

	@Override
	public int doStartTag() throws JspException {
		System.out.println("Ingredients.doStartTag()");
		return 0;
	}

	@Override
	public Tag getParent() {
		return parentTag;
	}

	@Override
	public void release() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setPageContext(PageContext pc) {
		this.pageContext = pc;
	}

	@Override
	public void setParent(Tag parentTag) {
		this.parentTag = parentTag;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setPrice(Double price) {
		this.price = price;
	}

}
